﻿using MediatR;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.Processiings_OneWay;
using Traceability_Management.Read.Api.Application.Command.Processiings_TwoWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.Processiings_TwoWay
{
    public class AddTwoWayCommandHandler : IRequestHandler<AddTwoWayCommand, ApiResult<int>>
    {
        IBaseReponsitory<Processiings_Two> Processiings_Two;

        public AddTwoWayCommandHandler(IBaseReponsitory<Processiings_Two> Processiings_Two)
        {
            this.Processiings_Two = Processiings_Two;
        }

        public async Task<ApiResult<int>> Handle(AddTwoWayCommand request, CancellationToken cancellationToken)
        {
            await Processiings_Two.AddAsync(request.Processiings_Two);
            return new ApiResult<int>
            {
                Code = ApiEnum.Success,
                Message = "添加成功",
                Data = 1
            };
        }
    }
}
